//
//  AppDelegate.m
//  17--WeekendHomework-02
//
//  Created by 冀永金 on 16/8/6.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 创建文件夹
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject] stringByAppendingPathComponent:@"path"];
    NSLog(@"%@",NSHomeDirectory());
    NSError *error = nil;
 BOOL isCreateSuccess = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
    if (isCreateSuccess) {
        NSLog(@"创建文件夹成功");
    }else {
        NSLog(@"创建文件夹失败");
    }
    NSString *filePath = [path stringByAppendingPathComponent:@"file.txt"];
    NSString *str = @"I Love you";
  BOOL isWriteFile =  [str writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
    
    if (isWriteFile) {
        NSLog(@"写入文件成功");
    }else {
        NSLog(@"写入文件失败");
    }
#if 0
 BOOL isRemove = [fileManager removeItemAtPath:filePath error:&error];
    if (isRemove) {
        NSLog(@"删除成功");
    }else {
        NSLog(@"删除失败");
    }
#endif
    
    NSString *filePath2 = [path stringByAppendingPathComponent:@"file2.txt"];
  BOOL isMove =  [fileManager moveItemAtPath:filePath toPath:filePath2 error:&error];
    if (isMove) {
        NSLog(@"移动成功");
    }else {
        NSLog(@"移动失败");
    }
    NSFileManager *managerOftmp = [NSFileManager defaultManager];
    NSString *textDirectory =[NSTemporaryDirectory() stringByAppendingPathComponent:@"testDirectory"];
    [managerOftmp createDirectoryAtPath:textDirectory withIntermediateDirectories:YES attributes:nil error:nil];
    NSString *test1 = [textDirectory stringByAppendingPathComponent:@"file1.txt"];
    [managerOftmp copyItemAtPath:filePath toPath:test1 error:&error];
    // Override point for customization after application launch.
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
